package one;
import java.util.*;

public class A009 {
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> ret = new ArrayList<>();
        int lenS = s.length();
        int lenP = p.length();
        if(lenS < lenP) return ret;
        //1.排序异位词
        char[] t = p.toCharArray();
        Arrays.sort(t);
        p = new String(t);
        //2.
        for(int left=0,right=lenP-1;right<lenS;right++) {
            String str = s.substring(left,right+1);
            char[] tt = str.toCharArray();
            Arrays.sort(tt);
            str = new String(tt);

            //判断和记录结果
            if(str.equals(p)) {
                ret.add(left);
            }
            left++;
        }
        return ret;
    }
}
